package com.decent.core.alarm.process.action;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.decent.common.bo.MessageBean;
import com.decent.core.alarm.entity.bo.AlarmBO;
import com.decent.core.alarm.model.AlarmModel;
import com.decent.core.alarm.process.AlarmBusiness;
import com.decent.core.alarm.process.AlarmProcessContext;
import com.decent.core.alarm.util.Validators;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

/**
 * 后置参数校验
 *
 * @author menghx
 */
@Slf4j
public class AlarmAfterParamCheckAction implements AlarmBusiness {
    @Resource
    private Validators validators;

    /**
     * 后置参数校验
     *
     * @param context 上下文
     */
    @Override
    public void process(AlarmProcessContext context) {
        AlarmModel sendModel = context.getProcessModel();
        String validMsg = validators.valid(sendModel.getAlarmBO(), AlarmBO.AfterCheck.class);
        if (StrUtil.isNotBlank(validMsg)) {
            log.warn("发送报警,后置参数校验失败[{}],context[{}]", validMsg, JSONUtil.toJsonStr(context));
            context.setNeedBreak(true).setResponse(MessageBean.fail("后置参数校验失败：" + validMsg));
        }
    }
}
